#coding=utf-8
import socket
import argparse
socket.setdefaulttimeout(0.01)
def port_scan(taghost,tagport):
    """ 这是一个例子程序 """
    
    try:
        s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
        s.connect((taghost,tagport))
        print "开放端口",tagport
        s.close()
    except:
        print "%s 这个端口没开放"% tagport
    finally:
        s.close()


if __name__ == '__main__':
    parser=argparse.ArgumentParser(description="这是我的第一个工具")
    parser.add_argument("-t","--taghost",help="输入扫描的目标ip")
    args=parser.parse_args()
    if args.taghost:
        for i in [21,22,23,139,443,445,80,8080,1389]:
            port_scan(args.taghost,i)
    else:
        print parser.format_help()

        